package com.smile67.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.smile67.common.restult.PageResult;
import com.smile67.common.restult.Result;
import com.smile67.pojo.dto.DeviceManagementPageQueryDTO;
import com.smile67.pojo.entity.DeviceManagement;
import com.smile67.mapper.DeviceManagementMapper;
import com.smile67.service.IDeviceManagementService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author smile67
 * @since 2023-09-07
 */
@Service
public class DeviceManagementServiceImpl extends ServiceImpl<DeviceManagementMapper, DeviceManagement> implements IDeviceManagementService {

    @Override
    public PageResult pageQuery(DeviceManagementPageQueryDTO deviceManagementPageQueryDTO) {
        //select * from employee limit 0,10
        Integer pageNo = deviceManagementPageQueryDTO.getPageNo();
        Integer pageSize = deviceManagementPageQueryDTO.getPageSize();

        Long id = deviceManagementPageQueryDTO.getId();
        Integer type = deviceManagementPageQueryDTO.getType();
        LocalDateTime createTime = deviceManagementPageQueryDTO.getCreateTime();
        Integer employeeId = deviceManagementPageQueryDTO.getEmployeeId();

        //分页构造器
        Page<DeviceManagement> page = new Page<>(pageNo, pageSize);

        LambdaQueryWrapper<DeviceManagement> wrapper = new LambdaQueryWrapper<DeviceManagement>()
                .eq(id!=null,DeviceManagement::getId,id)
                .eq(type!=null,DeviceManagement::getType,type)
                .eq(createTime!=null,DeviceManagement::getCreateTime,createTime)
                .eq(createTime!=null,DeviceManagement::getEmployeeId,employeeId);

        page = page(page,wrapper);
        return new PageResult(page.getTotal(),page.getRecords());
    }
}
